﻿@model Web.BaseModel
@{
    ViewBag.Title = "用户列表";
}

<div class="pageTitle">
    <p><img src="/css/image/tubiao_28.png" />您的位置：<span>@ViewBag.Title</span></p>
</div>
<div class="queryConditionDiv">
    <div class="queryText">
        <span>姓名：</span>
        <input type="text" id="Name" class="textinput" />

        <span>电话：</span>
        <input type="text" id="Phone" class="textinput" />
    </div>

    <input id="btnSearch" type="button" value="" class="queryButton" />
</div>

<div class="List_head">
    <div class="head_left"></div>
    <div class="head_bj">
        <div class="xiangxi">@ViewBag.Title</div>
        <a class="xinZeng" href="UserEdit"></a>
    </div>
    <div class="head_right"></div>
</div>

<div class="list_table" id="divTabel">
    <table class="dataShowTable" id="tb">
        <tr>
            <th>登陆名</th>
            <th>个人姓名</th>
            <th>角色</th>
            <th>公司</th>
            <th></th>
        </tr>

    </table>

    <div id="BOX_overlay">
        <div id="ajaxinfo"></div>
    </div>
</div>
<div id="divHidden">
    <input type="hidden" id="strWhere" />
    <input type="hidden" id="PageIndex" value="1" />
    <input type="hidden" id="TotalPages" value="1" />
</div>
<script type="text/javascript">
    var UrlAction = '@Url.Action("UserQuery")';

    $(function () {//页面加载完成执行
        getDataDrawTable("", 1, UrlAction);
        $("#btnSearch").click(search);
    });

    function del(self) {
        var id = $(self).parent().parent().attr('id');
        $.ajax({
            url: '@Url.Action("UserDelete")',
            data: { id: id },
            type: "POST",
            success: function (data) {
                var res = data;
                if (res.result) {
                    turnPage(parseInt($("#PageIndex").val()));
                } else {
                    alert(res.des);
                }
            },
            error: function (xhr, textStatus, error) {
                alert(error);
            }
        });
    }

    function search() {
        var strWhere = "";
        var LoginName = $("#LoginName").val();
        var Phone = $("#Phone").val();
        if ($.trim(LoginName) != "")
            strWhere += " AND LoginName LIKE '%" + LoginName + "%'";
        if ($.trim(Phone) != "")
            strWhere += " AND Phone LIKE '%" + Phone + "%'";

        getDataDrawTable(strWhere, 1, UrlAction);
    }

    function drawTable(list) {//success的回调函数
        removeAll("tb");
        var table = $("#tb");
        for (var i = 0; i < list.length; i++) {
            var tr = $("<tr>");
            tr.attr('id', list[i]["TUserId"]);

            tr.append($("<td class=''>" + format(list[i]["LoginName"]) + "</td>"));
            tr.append($("<td class=''>" + format(list[i]["PersonalName"]) + "</td>"));
            tr.append($("<td class=''>" + format(list[i]["TRoleId"]) + "</td>"));
            tr.append($("<td class=''>" + format(list[i]["CompanyId"]) + "</td>"));

            tr.append($("<td class=''>"
                + "<a href='UserEdit?Id=" + list[i]["TUserId"] + "'>修改</a>"
                + "<a href='javascript:void(0)' onclick='del(this)'>删除</a>"
                + "</td>"));
            tr.appendTo(table);
        }
    }

</script>
